package com.njtoyo.taxi.admin.rest.controller.platform;

import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.secondary.entity.AdminUser;
import com.njtoyo.taxi.admin.mapper.secondary.fields.FakeMultiple;
import com.njtoyo.taxi.admin.rest.presenter.platfrom.AdminUserAllPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DesignatedChargeWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.platform.adminUser.AdminUserListWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.platform.adminUser.AdminUserUpdateDefaultPointWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.platform.adminUser.AdminUserUpdateIdentityWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.platform.adminUser.AdminUserUpdateRoleWrapper;
import com.njtoyo.taxi.admin.service.platform.AdminUserService;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/platform/admin_user")
@Api(tags = "用户管理")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    @GetMapping("/all")
    @ApiOperation(value = "验证对象所有信息", notes = "验证对象所有信息,权限:")
    RestResult<List<AdminUserAllPresenter>> adminUserAll() {
        return adminUserService.adminUserAll();
    }

    @GetMapping("")
    @ApiOperation(value = "获取用户列表", notes = "权限: admin_user")
    @PermissionScope(names = {"admin_user"})
    public RestResult getList(@Valid AdminUserListWrapper adminUserListWrapper) {
        return adminUserService.findAdminUserPage(adminUserListWrapper);
    }

    @PatchMapping("/{id}/role")
    @ApiOperation(value = "修改用户角色", notes = "权限：admin_user_update_role")
    @PermissionScope(names = {"admin_user_update_role"})
    public RestResult updateRole(@PathVariable("id") Long id, @Valid @RequestBody AdminUserUpdateRoleWrapper updateRoleWrapper) {
        return adminUserService.updateRole(id, updateRoleWrapper);
    }

    @PatchMapping("/{id}/identity")
    @ApiOperation(value = "修改用户身份", notes = "权限：admin_user_update_identity")
    @PermissionScope(names = {"admin_user_update_identity"})
    public RestResult updateRole(@PathVariable("id") Long id, @Valid @RequestBody AdminUserUpdateIdentityWrapper updateWrapper) {
        return adminUserService.updateIdentity(id, updateWrapper);
    }

    @PatchMapping("/{id}/fake_multiple")
    @ApiOperation(value = "修改用户翻倍率", notes = "权限：admin_user_update_fake_multiple")
    @PermissionScope(names = {"admin_user_update_fake_multiple"})
    public RestResult updateFakeMultiple(@PathVariable("id") Long id, @Valid @RequestBody FakeMultiple updateWrapper) {
        return adminUserService.updateFakeMultiple(id, updateWrapper);
    }

    @PatchMapping("/{id}/default_point")
    @ApiOperation(value = "修改用户默认坐标", notes = "权限：admin_user_update_default_point")
    @PermissionScope(names = {"admin_user_update_identity"})
    public RestResult updateDefaultPoint(@PathVariable("id") Long id, @Valid @RequestBody AdminUserUpdateDefaultPointWrapper updateWrapper) {
        return adminUserService.updateDefaultPoint(id, updateWrapper);
    }

    @PostMapping
    @PermissionScope(names = {"admin_user_create"})
    public RestResult create(@RequestBody AdminUser adminUser) {
        return adminUserService.create(adminUser);
    }

    @PostMapping("/updateState")
    RestResult updateState(@RequestBody Map<String,Object> param) {
        return adminUserService.updateState(param);
    }

}
